package com.eonmind.user.controller;

import com.eonmind.common.contract.data.response.PageResponse;
import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.user.contract.dto.UserInfoData;
import com.eonmind.user.dto.UserNoticeDto;
import com.eonmind.user.service.INoticeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户通知配置控制类
 *
 * @author Xujie
 * @since 2025/6/1 13:01
 **/

@RestController
public class UserNoticeController {

    @Resource
    private INoticeService noticeService;

    /**
     * 获取用户通知配置
     *
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/user/notice/preference")
    public ResponseEntity<List<UserNoticeDto.UserNoticePreferenceResponse>> getUserNoticePreference(UserInfoData userInfoData) {
        return ResponseEntity.success(noticeService.userNoticePreference(userInfoData));
    }

    /**
     * 更新用户通知配置
     *
     * @param userNoticePreferenceUpdateRequest
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/user/notice/preference/update")
    public ResponseEntity<Boolean>
    updateUserNoticePreference(UserInfoData userInfoData,
                               @RequestBody UserNoticeDto.UserNoticePreferenceUpdateRequest userNoticePreferenceUpdateRequest) {
        return ResponseEntity.success(noticeService.updateUserNoticePreference(userInfoData, userNoticePreferenceUpdateRequest));

    }

    /**
     * 获取用户通知分页
     *
     * @param userNoticePageRequest
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/user/notice/page")
    public ResponseEntity<PageResponse<UserNoticeDto.UserNoticeData>>
    getUserNoticePage(UserInfoData userInfoData,
                      @RequestBody UserNoticeDto.UserNoticePageRequest userNoticePageRequest) {
        return ResponseEntity.success(noticeService.getUserNoticePage(userInfoData, userNoticePageRequest));
    }

    /**
     * 批量删除用户通知
     *
     * @param userNoticeDelRequest
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/user/notice/del")
    public ResponseEntity<Boolean>
    delUserNotice(UserInfoData userInfoData,
                  @RequestBody UserNoticeDto.UserNoticeDelRequest userNoticeDelRequest) {
        return ResponseEntity.success(noticeService.delUserNotice(userInfoData, userNoticeDelRequest));
    }

    /**
     * 批量更新用户通知状态
     *
     * @param userInfoData
     * @param userNoticeStatusUpdateRequest
     * @return
     */
    @UserInfo
    @PostMapping("/user/notice/status")
    public ResponseEntity<Boolean>
    updateUserNoticeStatus(UserInfoData userInfoData,
                           @RequestBody UserNoticeDto.UserNoticeStatusUpdateRequest userNoticeStatusUpdateRequest) {
        return ResponseEntity.success(noticeService.updateUserNoticeStatus(userInfoData, userNoticeStatusUpdateRequest));
    }
}
